<template>
	<view class="container">
		<uni-easyinput v-model="data.name" placeholder="请输入账号"></uni-easyinput>
		<uni-easyinput v-model="data.password" placeholder="请输入密码" style="margin-top: 50rpx;" type="password">
		</uni-easyinput>
		<button type="primary" @click="login" style="margin-top: 50rpx;">登录</button>
		<button type="default" @click="reg" style="margin-top: 50rpx;">注册</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: {
					"name": "",
					"password": ""
				}
			}
		},
		methods: {
			login() {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/user/login',
					method: 'POST',
					data: this.data,
					success: res => {
						console.log(res);
						if (res.data.success) {
							this.data = res.data.data
							uni.showToast({
								icon: 'none',
								title: '登录成功'
							});
						uni.setStorageSync("user",res.data.data)
							uni.switchTab({
								url:"/pages/my/my"
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: '登录失败'
							});
						}
					},
					fail: () => {
						uni.showToast({
							icon: 'none',
							title: '失败'
						});
					},
					complete: () => {}
				});
			},
			reg() {
				uni.navigateTo({
					url: '/pages/reg/reg'
				})
			}
		},
		onLoad() {

		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
